package com.mangowang.module.main.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.protobuf.InvalidProtocolBufferException;
import com.mangowang.lib.common.base.BaseActivity;
import com.mangowang.lib.common.net.Apis;
import com.mangowang.lib.common.net.NetworkManager;
import com.mangowang.lib.common.net.interfaces.OnRequestCallBack;
import com.mangowang.lib.common.proto.MemberBank;
import com.mangowang.lib.common.util.StatusBarUtil;
import com.mangowang.lib.common.util.ValidateUtils;
import com.mangowang.module.main.R;
import com.mangowang.module.main.R2;
import com.ruffian.library.widget.RTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class BankCardActivity extends BaseActivity {


    Unbinder unbinder;
    @BindView(R2.id.tv_title)
    TextView tvTitle;
    @BindView(R2.id.tv_bank_name)
    TextView tvBankName;
    @BindView(R2.id.tv_card_number)
    TextView tvCardNumber;
    @BindView(R2.id.btn_add_card)
    RTextView btnAddCard;
    @BindView(R2.id.back_iv)
    ImageView backIv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bank_card);
        ButterKnife.bind(this);
        StatusBarUtil.setStatusBarLightMode(this, Color.parseColor("#FFFFFF"), true);
        tvTitle.setText("银行卡");
        backIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        btnAddCard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(BindBankPayActivity.class);
            }
        });

    }


    @Override
    protected void onResume() {
        super.onResume();
        isBindBankCard();
    }
    // 加载检查是否有绑定银行卡
    private void isBindBankCard() {




        NetworkManager.INSTANCE.post(Apis.member_bank, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) throws InvalidProtocolBufferException {
                MemberBank.get_bank bean = MemberBank.get_bank.parseFrom(response);
                List<MemberBank.bank> datas = bean.getArrayList();
                if (ValidateUtils.isValidate(datas)) {
                    String bank_card = datas.get(0).getBankCard();
                    String substring = bank_card.substring(bank_card.length() - 4);
                    tvBankName.setText(datas.get(0).getBankName());
                    tvCardNumber.setText("**** **** **** " + substring);
                    btnAddCard.setText("换绑银行卡");
                }

            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                showToast(errorMessage);
            }
        });
    }


}


